package com.itheima.pinda.authority.config;

import com.itheima.pinda.authority.biz.service.common.OptLogService;
import com.itheima.pinda.log.entity.OptLogDTO;
import com.itheima.pinda.log.event.SysLogEvent;
import com.itheima.pinda.log.event.SysLogListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.function.Consumer;

/**
 * @Description: 系统操作日志配置
 * @Author: ysf
 * @CreateTime: 2024-11-13  17:43
 * @Version: 1.0
 */
@EnableAsync
@Configuration
public class SysLogConfiguration {

    //日志记录监听器
    @Bean
    public SysLogListener sysLogListener(OptLogService optLogService){
        //匿名内部类方式
//        Consumer<OptLogDTO> consumer = new Consumer<OptLogDTO>() {
//            @Override
//            public void accept(OptLogDTO optLogDTO) {
//                optLogService.save(optLogDTO);
//            }
//        };
        //lambda表达式简写匿名内部类
        Consumer<OptLogDTO> consumer = (optLogDTO) -> optLogService.save(optLogDTO);
        return new SysLogListener(consumer);
    }
}
